package org.jobtask.ui;

import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import org.jobtask.schedule.JobState;
import org.jobtask.schedule.JobTask;

public class ListLabel extends JLabel implements ListCellRenderer{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1908824333453251600L;

	public ListLabel(){
		this.setOpaque(true);
	}

	@Override
	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) {
		if (value != null)
        {
                setText(value.toString());
                setFont(UIConst.FONT16);
            	JobTask jjtt=(JobTask)value;
            	if(jjtt.getState().equals(JobState.STOP)){
                     setIcon(new ImageIcon(this.getClass().getResource("images/stop.png")));
            	}else{
            		setIcon(new ImageIcon(this.getClass().getResource("images/run.png")));
            	}
            	list.repaint();
        }
		
        if (isSelected) {
            setBackground(list.getSelectionBackground());
            setForeground(list.getSelectionForeground());
            setBorder(BorderFactory.createLoweredBevelBorder());
          setIcon(new ImageIcon(this.getClass().getResource("images/selected.png")));
        }else {
        	setBorder(BorderFactory.createEmptyBorder());
            setBackground(list.getBackground());
            setForeground(list.getForeground());
        }
        return this;
	}
}
